// interface Element {
//   time:intervalId
// }
function animate(obj: any, target: number, cllback?: Function) {
  clearInterval(obj.time); //清除前面的定时器防止重复点击叠加定时器
  obj.time = setInterval(function () {
    if (obj.offsetLeft == target) {
      //执行结束清除定时器
      clearInterval(obj.time);
      cllback && cllback();
    }
    if (target - obj.offsetLeft > 0) {
      var te = Math.ceil((target - obj.offsetLeft) / 10); //向上取整
    } else {
      var te = Math.floor((target - obj.offsetLeft) / 10); //向上取整
    }
    obj.style.left = obj.offsetLeft + te + "px";
  }, 10);
}
export default animate;
